package com.example.dbmeta.exception;

import java.text.MessageFormat;

public enum DbMetaErrorCode {
    // 文件相关错误
    CONFIG_FILE_NOT_FOUND(1001, "配置文件未找到: {0}"),
    CONFIG_PARSE_ERROR(1002, "配置文件解析失败: {0}"),

    // 配置验证错误
    DUPLICATE_DATA_INSTANCE(2001, "发现重复的数据源实例名称: {0}"),
    MISSING_DATA_INSTANCE_NAME(2002, "数据源实例缺少有效的 dbinstancename"),
    INVALID_DATASOURCE_URL(2003, "{0}: URL无效"),
    MISSING_DRIVER_CLASS(2004, "{0}: 缺少驱动类名"),
    INVALID_KEEPDAYS(2005, "保留天数无效, 必须在{0}-{1}之间, 当前值: {2}"),
    MISSING_DEST_DATASOURCE(2006, "目标数据源配置缺失"),
    MISSING_DEST_URL(2007, "目标数据源URL缺失"),
    MISSING_DEST_DRIVER(2008, "目标数据源驱动类名缺失"),

    // 系统错误
    SYSTEM_STARTUP_FAILED(5001, "系统启动失败"),
    DATABASE_CONNECTION_FAILED(5002, "数据库连接失败: {0}"),

    // 通用错误
    INVALID_CONFIG(6001, "配置无效: {0}");

    private final int code;
    private final String messageTemplate;

    DbMetaErrorCode(int code, String messageTemplate) {
        this.code = code;
        this.messageTemplate = messageTemplate;
    }

    public int getCode() {
        return code;
    }

    public String getMessage(Object... params) {
        return MessageFormat.format(messageTemplate, params);
    }
}